package com.xique.park.controller.web;

import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.domain.PageResult;
import com.xique.park.bean.request.web.refund.RefundOrderRequest;
import com.xique.park.service.service.IRefundOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 退款记录 controller
 *
 * @author WLD
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/refundOrder")
public class WebRefundOrderController {

    private final IRefundOrderService refundOrderService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody(required = false) RefundOrderRequest request) {
        request = checkParam(request);
        PageResult pageResult = refundOrderService.selectPageList(request);
        return AjaxResult.success(pageResult);
    }

    /**
     * 导出
     */
    @PostMapping("/export")
    public void export(@RequestBody(required = false) RefundOrderRequest request, HttpServletResponse response) {
        request = checkParam(request);
        refundOrderService.export(request, response);
    }

    private RefundOrderRequest checkParam(RefundOrderRequest request) {
        if (request == null) {
            request = new RefundOrderRequest();
        }
        int pageNum = request.getPageNum() == null ? 1 : request.getPageNum();
        int pageSize = request.getPageSize() == null ? 10 : request.getPageSize();
        if (request.getParkId() == null) {
            Long parkId = SecurityUtils.getParkId();
            if (parkId != null) {
                request.setParkId(parkId);
            }
        }
        request.setPageNum(pageNum);
        request.setPageSize(pageSize);
        return request;
    }

}
